import java.util.Arrays;

public class demo1 {
    class Solution {
        public int thirdMax(int[] nums) {
            int n=nums.length;
            if(n==1)return nums[0];
            if(n==2)return Math.max(nums[0],nums[1]);
            Arrays.sort(nums);
            int ret=Integer.MIN_VALUE;
            int count=0;
            for(int i=n-1;i>=0;i--){
                if(ret<nums[i]){
                    count++;
                    ret=nums[i];
                }
                if(count==3)break;
            }
            return ret;
        }
    }
}
